Dong ho 60 led vien
#include<reg52.h>
sbit DATA1 = P2^7;
sbit SCK1 = P2^6;
sbit LACH1 = P2^5;
sbit set=P3^5;
sbit up=P3^6;
sbit down=P3^7;
sbit sdi1 = P3^1;
sbit str1 = P3^2;
sbit clk1 = P3^0;
unsigned char m1[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
unsigned char m2[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char m3[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
unsigned char hour, minute, second,c;
unsigned char ma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char kt=0,a=0,i,k,x=0,cap_nhap_hien_thi;
bit set0=1,set1=1,up0=1,up1=1,down0=1,down1=1;
sbit SCL = P1^0;
sbit SDA = P1^1;
void delay(){
unsigned char i;
for (i = 0; i < 4; i++){};
}
//-----------------------------------------
void SCL_high(){
SCL = 1;
delay();
}
//------------------------------------------
void SCL_low(){
SCL = 0;
delay();
}
//-------------------------------------------
void I2C_Start(){
SDA = 1;
SCL = 1;
SDA = 0;
delay();
SCL = 0;
SDA = 1;
}
//--------------------------------------------
void I2C_Stop(){
SDA = 0;
SCL_high();
SDA = 1;
}
//----------------------------------------------
bit I2C_Write(unsigned char dat){
unsigned char i;
bit outbit;
for (i = 1; i <= 8; i++){
outbit=dat&0x80;
SDA = outbit;
dat = dat << 1;
SCL_high();
SCL_low();
}
SDA = 1;
SCL_high();
outbit = SDA;
SCL_low();
return(outbit);
}
//----------------------------------------------------
unsigned char I2C_Read(bit ack){
unsigned char i, dat;
bit inbit;
dat = 0;
for(i=1;i<=8;i++) {
SCL_high();
inbit = SDA;
dat = dat << 1;
dat = dat | inbit;
SCL_low();
}
if (ack) SDA = 0;
else SDA = 1;
SCL_high();
SCL = 0;
SDA = 1;
delay();
return(dat);
}
//-------------------------------------------------------------
void rtc_write(unsigned char add, unsigned char dat){
I2C_Start();
I2C_Write(0xd0);
I2C_Write(add);
I2C_Write(((dat/10)<<4)|(dat%10));
I2C_Stop();
}
unsigned char rtc_read(unsigned char add){
unsigned char dat;
I2C_Start();
I2C_Write(0xd0);
I2C_Write(add);
I2C_Start();
I2C_Write(0xd1);
dat = I2C_Read(0);
I2C_Stop();
dat = (dat & 0x0f) + (dat>>4)*10;
return (dat);
}
void writeds(){
rtc_write(0x00, second);
rtc_write(0x01, minute);
rtc_write(0x02, hour);
}
void readds()
{
if(kt==0)
{
if(a==1)
{writeds();a=0;
}
second = rtc_read(0x00);
minute = rtc_read(0x01);
hour = rtc_read(0x02);
}
}
void hienthi(unsigned char x)
{
unsigned int i,temp;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA1=1;
else
DATA1=0;
x*=2;
SCK1=0;
SCK1=1;
}
}
void quetled()
{
if(kt==0)
{
if(cap_nhap_hien_thi==second)
{}
else{//với thiết kế phần cứng kiểu này thì khi phần giây thay đổi mới cho hiển thị dữ liệu mới.
cap_nhap_hien_thi=second;
//xoa bong mo
hienthi(0xff);hienthi(0xff);hienthi(0xff);
hienthi(0xff);hienthi(0xff);hienthi(0xff);
LACH1=0;LACH1=1;delay();
hienthi(ma[second%10]);
hienthi(ma[second/10]);
hienthi(ma[minute%10]);
hienthi(ma[minute/10]);
hienthi(ma[hour%10]);
hienthi(ma[hour/10]);
LACH1=0;
LACH1=1;}
}
if(kt==1)
{
hienthi(0xff);
hienthi(0xff);
hienthi(0xff);
hienthi(0xff);
hienthi(ma[hour%10]);
hienthi(ma[hour/10]);
LACH1=0;
LACH1=1;
}
if(kt==2)
{
hienthi(0xff);
hienthi(0xff);
hienthi(ma[minute%10]);
hienthi(ma[minute/10]);
hienthi(0xff);
hienthi(0xff);
LACH1=0;
LACH1=1;
}
if(kt==3)
{
hienthi(ma[second%10]);
hienthi(ma[second/10]);
hienthi(0xff);
hienthi(0xff);
hienthi(0xff);
hienthi(0xff);
LACH1=0;
LACH1=1;
}
}
void ktphim()
{
set0=set1;set1=set;
if((set0==1)&&(set1==0))
{
kt++;
if(kt>3)kt=0;
}
switch(kt)
{
case 0:break;
case 1:
{
up0=up1;up1=up; a=1;
if((up0==1)&&(up1==0))
{
hour++;
if(hour>23)hour=0;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
hour--;
if(hour==-1)
hour=23;
}
break;
}
case 2:
{
up0=up1;up1=up; a=1;
if((up0==1)&&(up1==0))
{
minute++;
if(minute>59)
minute=0;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
minute--;
if(minute==-1)
minute=59;
}
break;
}
case 3:
{
up0=up1;up1=up;a=1;
if((up0==1)&&(up1==0))
{
second++;
if(second>59)
second++;
}
down0=down1;down1=down;
if((down0==1)&&(down1==0))
{
second=0;
}
break;
}
}
}
void ghi_dich(unsigned char t1,unsigned char t2,unsigned char t3,unsigned char t4,unsigned char t5,unsigned char t6,unsigned char t7,unsigned char t8)
{unsigned char i,Q;
Q=t8; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t7; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t6; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t5; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t4; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t3; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t2; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
Q=t1; for(i=0;i<8;i++){sdi1=(Q&0x01)?1:0;clk1=1;clk1=0;Q>>=1; }
str1=0; str1=1;
}
void sosanh(unsigned char gia_tri)
{unsigned char k1,k2,k3;
k1=0;k2=m1[gia_tri%8];k3=0xff;
if((gia_tri>=0)&&(gia_tri<8)) ghi_dich(k2,k3,k3,k3,k3,k3,k3,k3);
if((gia_tri>=8)&&(gia_tri<16)) ghi_dich(k1,k2,k3,k3,k3,k3,k3,k3);
if((gia_tri>=16)&&(gia_tri<24))ghi_dich(k1,k1,k2,k3,k3,k3,k3,k3);
if((gia_tri>=24)&&(gia_tri<32))ghi_dich(k1,k1,k1,k2,k3,k3,k3,k3);
if((gia_tri>=32)&&(gia_tri<40))ghi_dich(k1,k1,k1,k1,k2,k3,k3,k3);
if((gia_tri>=40)&&(gia_tri<48))ghi_dich(k1,k1,k1,k1,k1,k2,k3,k3);
if((gia_tri>=48)&&(gia_tri<56))ghi_dich(k1,k1,k1,k1,k1,k1,k2,k3);
if((gia_tri>=56)&&(gia_tri<60))ghi_dich(k1,k1,k1,k1,k1,k1,k1,k2);
}
void main()
{
I2C_Start();
I2C_Write(0xD0);
I2C_Write(0x07);
I2C_Write(0x10);
I2C_Stop();
while(1)
{
ktphim();
readds();
quetled();
sosanh(second);
}
}
Read more: http://codientu.org/threads/xin-giup-minh-led-7seg-dung-74hc59-bi-hung-led.3864/page-3#ixzz2P8157LAf
mã nguồn cơ bản bằng cách sử dụng Keil uVision3
#include "reg52.h"
//------------------------------------------------------------------------------------------
#define uchar unsigned char
#define uint unsigned int
//
sbit S_DIO = P3^0;
sbit S_CLK = P3^1;
sbit R_CLK = P3^2;
//
sbit KEY_1 = P1^1;
sbit KEY_2 = P1^2;
sbit KEY_3 = P1^0;
//
sbit BEEP = P2^7;
//
sbit T_CLK = P3^5;
sbit T_IO = P3^6;
sbit T_RST = P3^7;
sbit ACC0 = ACC^0;
sbit ACC1 = ACC^1;
sbit ACC2 = ACC^2;
sbit ACC3 = ACC^3;
sbit ACC4 = ACC^4;
sbit ACC5 = ACC^5;
sbit ACC6 = ACC^6;
sbit ACC7 = ACC^7;
//------------------------------------------------------------------------------------------
unsigned char code font[][7]={
0x38,0x44,0x64,0x54,0x4C,0x44,0x38,//0xF8,0x88,0x88,0x88,0x88,0x88,0xF8, //-----------'0'
0x10,0x18,0x10,0x10,0x10,0x10,0x38,//0x20,0x30,0x28,0x20,0x20,0x20,0xF8, //-----------'1'
0x38,0x44,0x40,0x20,0x10,0x08,0x7C,//0xF8,0x80,0x80,0xF8,0x08,0x08,0xF8, //-----------'2'
0x7C,0x20,0x10,0x20,0x40,0x44,0x38,//0xF8,0x80,0x80,0xF8,0x80,0x80,0xF8, //-----------'3'
0x20,0x30,0x28,0x24,0x7C,0x20,0x20,//0x48,0x48,0x48,0x48,0xF8,0x40,0x40, //-----------'4'
0x7C,0x04,0x3C,0x40,0x40,0x44,0x38,//0xF8,0x08,0x08,0xF8,0x80,0x80,0xF8, //-----------'5'
0x70,0x08,0x04,0x3C,0x44,0x44,0x38,//0xF8,0x08,0x08,0xF8,0x88,0x88,0xF8, //-----------'6'
0x7C,0x40,0x20,0x10,0x08,0x08,0x08,//0xF8,0x80,0x80,0x80,0x80,0x80,0x80, //-----------'7'
0x38,0x44,0x44,0x38,0x44,0x44,0x38,//0xF8,0x88,0x88,0xF8,0x88,0x88,0xF8, //-----------'8'
0x38,0x44,0x44,0x78,0x40,0x20,0x1C,//0xF8,0x88,0x88,0xF8,0x80,0x80,0x80, //-----------'9'
0x00,0x30,0x30,0x00,0x30,0x30,0x00, //-----10----':'
0x00,0x00,0x00,0x00,0x00,0x00,0x00, //-----11----' '
};
unsigned char idata DisTemp[5][7];
unsigned char idata Dis[5]={1,2,10,0,0};
//------------------------------------------------------------------------------------------
//-----------------------------
unsigned char idata Time[7];
//------------------------------------------------------------------------------------------
unsigned char idata CSRow[7]={0x01,0x02,0x04,0x08,0x10,0x20,0x40};
unsigned char idata second,minute,hour,day,month,week,year;
unsigned long int idata Disbuf[5];
unsigned long int idata Disbuftemp[7];
//------------------------------------------------------------------------------------------
/*******************************************************************************************
*
*******************************************************************************************/
void Delay(unsigned int i)
{
unsigned int j;
for(j=0;j<i;j++);
}
/*******************************************************************************************
*
*******************************************************************************************/
void OutData(unsigned char Data)
{
SBUF=~Data;
while(TI==0);
TI=0;
}
/*******************************************************************************************
*
*******************************************************************************************/
unsigned char BCD2HEX(unsigned char BCDChar)
{
unsigned char temp;
temp=(BCDChar/16*10+BCDChar%16);
return temp;
}
/*******************************************************************************************
*
*******************************************************************************************/
unsigned char HEX2BCD(unsigned char HEXChar)
{
unsigned char temp;
temp=(HEXChar/10*16+HEXChar%10);
return temp;
}
/*******************************************************************************************
*
*******************************************************************************************/
void WriteByteDS1302(unsigned char Data)
{
unsigned char i;
ACC = Data;
for(i=8; i>0; i--)
{
T_IO = ACC0;
T_CLK = 1;
T_CLK = 0;
ACC = ACC >> 1;
}
}
/*******************************************************************************************
*
*******************************************************************************************/
unsigned char ReadByteDS1302(void)
{
unsigned char i;
for(i=8; i>0; i--)
{
ACC = ACC >>1;
ACC7 = T_IO;
T_CLK = 1;
T_CLK = 0;
}
return(ACC);
}
/*******************************************************************************************
*
*******************************************************************************************/
void WriteDS1302(unsigned char Addr,unsigned char Data)
{
T_RST = 0;
T_CLK = 0;
T_RST = 1;
WriteByteDS1302(Addr);
WriteByteDS1302(Data);
T_CLK = 1;
T_RST = 0;
}
/*******************************************************************************************
*******************************************************************************************/
unsigned char ReadDS1302(unsigned char Addr)
{
unsigned char Data;
T_RST = 0;
T_CLK = 0;
T_RST = 1;
WriteByteDS1302(Addr);
Data = ReadByteDS1302();
T_CLK = 1;
T_RST = 0;
return(Data);
}
/*******************************************************************************************
*
*******************************************************************************************/
void Set(unsigned char sel,unsigned char selby)
{
unsigned char address,item;
unsigned char max,min;
if(sel==0) {address=0x80; max=59;min=0;} //
if(sel==1) {address=0x82; max=59;min=0;} //
if(sel==2) {address=0x84; max=23;min=0;} //
if(sel==3) {address=0x86; max=31;min=1;} //
if(sel==4) {address=0x88; max=12;min=1;} //
if(sel==5) {address=0x8a; max=7; min=1;} //
if(sel==6) {address=0x8c; max=99;min=0;} //
if(sel==7) {address=0xc0; max=59;min=0;} //
if(sel==8) {address=0xc2; max=23;min=0;} //
item=ReadDS1302(address 1)/16*10 ReadDS1302(address 1)%16;
if (selby==0) item ; else item--;
if(item>max) item=min;
if(item<min) item=max;
WriteDS1302(0x8e,0x00);
WriteDS1302(address,item/10*16 item%10);
WriteDS1302(0x90,0xa5);
WriteDS1302(0x8e,0x80);
}
/*******************************************************************************************
*
*******************************************************************************************/
void SetTime(unsigned char*pClock)
{
unsigned char h;
unsigned char Addr=0x80;
WriteDS1302(0x8e,0x00);
for(h=7; h>0; h--)
{
WriteDS1302(Addr,*pClock);
pClock ;
Addr =2;
}
WriteDS1302(0x90,0xa5);
WriteDS1302(0x8e,0x80);
}
/*******************************************************************************************
*
*******************************************************************************************/
void ReadTime()
{
second = BCD2HEX(Time[0]=ReadDS1302(0x81));
minute = BCD2HEX(Time[1]=ReadDS1302(0x83));
hour = BCD2HEX(Time[2]=ReadDS1302(0x85));
day = BCD2HEX(Time[3]=ReadDS1302(0x87));
month = BCD2HEX(Time[4]=ReadDS1302(0x89));
year = BCD2HEX(Time[5]=ReadDS1302(0x8d));
week = BCD2HEX(Time[6]=ReadDS1302(0x8b));
}
/*******************************************************************************************
*
*******************************************************************************************/
void WriteTime()
{
WriteDS1302(0x8e,0x00);
WriteDS1302(0x80,HEX2BCD(second));
WriteDS1302(0x82,HEX2BCD(minute));
WriteDS1302(0x84,HEX2BCD(hour));
WriteDS1302(0x86,HEX2BCD(day));
WriteDS1302(0x88,HEX2BCD(month));
WriteDS1302(0x8A,HEX2BCD(week));
WriteDS1302(0x8C,HEX2BCD(year));
WriteDS1302(0x90,0xa5);
WriteDS1302(0x8e,0x80);
}
/*******************************************************************************************
*
*******************************************************************************************/
void DisProcess()
{
unsigned char i,j;
for(i=0;i<5;i )
for(j=0;j<7;j )
DisTemp[i][j]=font[Dis[i]][j];
for(i=0;i<7;i )
{
Disbuf[0]=DisTemp[4][i];
Disbuf[1]=DisTemp[3][i];
Disbuf[2]=DisTemp[2][i];
Disbuf[3]=DisTemp[1][i];
Disbuf[4]=DisTemp[0][i];
Disbuftemp[i]=Disbuf[0]<<24|Disbuf[1]<<18|Disbuf[2]<<12|Disbuf[3]<<6|Disbuf[4];
}
}
/*******************************************************************************************
*
*******************************************************************************************/
void DisPlay()
{
unsigned char i,j;
for(i=0;i<7;i )
{
P2=~0x00;
BEEP=1;
for(j=0;j<4;j )
OutData(0x00);
R_CLK=1;R_CLK=0;
P2=~CSRow[i];
BEEP=1;
for(j=0;j<4;j )
OutData(((unsigned char*)&Disbuftemp[i])[3-j]);
R_CLK=1;R_CLK=0;
Delay(350);
}
P2=~0x00;
BEEP=1;
for(j=0;j<4;j )
OutData(0x00);
R_CLK=1;R_CLK=0;
}
/*******************************************************************************************
*
*******************************************************************************************/
void init(void)
{
EA=1;
SCON=0;//
ReadTime();//
DisPlay();
Dis[0]=hour/10;
Dis[1]=hour%10;
Dis[3]=minute/10;
Dis[4]=minute%10;
Dis[2]=10;
DisProcess();
}
/*******************************************************************************************
*
*******************************************************************************************/
void main()
{
init();
while(1)
{
ReadTime();
DisPlay();
if((hour/10)==0)
{
Dis[0]=11;
}
else
{
Dis[0]=hour/10;
}
Dis[1]=hour%10;
Dis[3]=minute/10;
Dis[4]=minute%10;
if((second%10)%2)
Dis[2]=11;
else
Dis[2]=10;
DisProcess();
if(KEY_1==0)
{
DisPlay();
if(KEY_1==0)
{
Set(2,0);
}
while(KEY_1==0)DisPlay();
}
if(KEY_2==0)
{
DisPlay();
if(KEY_2==0)
{
Set(1,0);
}
while(KEY_2==0)DisPlay();
}
if(KEY_3==0)
{
DisPlay();
if(KEY_3==0)
{
WriteDS1302(0x8e,0x00);//
WriteDS1302(0x80,0x00);//
WriteDS1302(0x90,0xa5);//
WriteDS1302(0x8e,0x80);//
}
while(KEY_3==0)DisPlay();
}
}
}
Code dong ho 2
; DONG HO VA LED MATRAN5x7 nho
; CHIP 89S52
; XTAT 24.0MHz
;*******************************
;*******************************
;KHAI BAO CAC BIY NHO RAM
SET0 BIT 0x20.5
SET1 BIT 0x20.0
UP0 BIT 0x20.1
UP1 BIT 0x20.2
DOWN0 BIT 0x20.3
DOWN1 BIT 0x20.4
TITGIO BIT 0x20.6
HOANGIAY BIT 0x20.7
BIT12 BIT 0X21.0
AM_PM BIT 0X21.1
;***********************
;KHAI BAO CAC BIEN NHO RAM
; DONG HO
GIO EQU 10H
PHUT EQU 11H
GIAY EQU 12H
; THU EQU 13H
; NGAY EQU 14H
; THANG EQU 15H
; NAM EQU 16H
TEM EQU 08H
DAT EQU 09H
;**************************
MODE_K EQU R4
CHE_DO EQU R3
X EQU R5
; MODE_12_24 EQU R6
TAM1 EQU 17H
TAM2 EQU 18H
TAM3 EQU 19H
TAM4 EQU 1AH
GIOH_THI EQU 1BH
MODE_NAO EQU 1CH
;*************************
;*******************************
;PHIM BAM CHINH GIO
PHIMDN BIT P3.3; PHIM1
PHIMSE BIT P3.2; PHIM2
PHIMUP BIT P3.4; PHIM3
PHIM12_24 BIT P3.5
LOA BIT P1.7;.7;kich IC NHAC
;******************************************
;QUETLED hien thi gom 40 cot va 7 hang
SCK BIT P1.1 ;pin 11 74HC595
RCK BIT P1.2 ;pin 12 74HC595
SI BIT P1.0 ;pin 14 74HC595
XOA BIT P1.3;pin 10 74HC595
; SCL BIT P3.0 ;du tru khi sdung DS1307
; SDA BIT P3.1
;*******************************************
CHONHANG EQU P2;CHONHANG PORT P2
;hang 1>7 p2=00H>>08H
; su dung 40 byte ram tu 30h den 53h ;40 BYTE RAM
;****************************************
;************BAT DAU CHUONG TRINH ********
;******************************************
ORG 0000H
LJMP MAIN
; ORG 0003H
;LJMP EX0ISR
ORG 000BH ;Dia chi vector bo dinh thoi 0
LJMP T0ISR
ORG 001BH ;Dia chi vector bo dinh thoi 1
LJMP T1ISR ;tao am thanh bipbip
; ORG 002BH ;Dia chi vector bo dinh thoi 2
;***************************************
ORG 0030H
;**************************
MAIN : MOV SP,#60H
MOV TMOD,#11H;11H ;Ca 2 bo dinh thoi che do 1
MOV IE,#8AH ;8A;cho phep ngat do cac bo dinh thoi
MOV TAM4,#0
;************************************
MOV MODE_K,#0
MOV CHE_DO,#0
MOV X,#0
SETB SET0
SETB SET1
SETB UP0
SETB UP1
SETB DOWN0
SETB DOWN1
CLR TITGIO
CLR HOANGIAY
;***************************************
;LCALL KHOITAO
LCALL DOC12_24
LCALL BET
;===============================================
;***********CHUONG TRINH CHINH**************
PLAY: INC X
; LCALL KT_PHIM
MOV A,CHE_DO;,MODE_K
CJNE A,#0,K_DOC
LCALL DOCDONGHO12C887
;LCALL DOCDONGHODS1307
K_DOC:
LCALL QUETLED
LCALL KT_PHIM
CJNE X,#25,EXIT
MOV X,#0
JNB TITGIO,EXIT
MOV A,GIOH_THI
CJNE A,#00H,_TITGIO
JMP NO_TIT
_TITGIO:MOV A,TAM4;INC TAM4
LCALL _INC
MOV TAM4,A
LCALL BET
MOV A,GIOH_THI;GIO
CJNE A,TAM4,EXIT
MOV TAM4,#0
NO_TIT: CLR TITGIO
EXIT: LJMP PLAY
;***************************
;******************************
#include <DHO_DS12C887ASM.ASM>
;#include <DHO_DS1307ASM.ASM>
#include <QUETPHIMCHINHGIOPHUTGIAY.ASM>
#include <LOAD_DATA_QUETLED5X7.ASM>
;**************************
;**************************
;***********CHUONG TRINH NGAT TIME**************
T0ISR : CLR TR0 ; dung bo dinh thoi
MOV TH0,#HIGH(-50000)
MOV TL0,#LOW(-50000)
CLR TR1
CLR TF1
SETB TR0
E_TO : RETI
;**************************
;--------------------------------------------
T1ISR : CLR TR1 ; dung bo dinh thoi
MOV TH1,#HIGH(-320)
MOV TL1,#LOW(-320)
CPL LOA
SETB TR1
RETI
;**************************
;--------------------------------------------
BET: SETB TR0
SETB TF0
SETB TR1
SETB TF1
RET
;*********************
CHOPSANG:MOV A,X ; neu x>15 thi tat led
SETB C
SUBB A,#12
RET
;***********************
;;--------------------------------------------
;--------------------------------------------
END
chương trình chính này được sử dụng cho cả hai con ds12887 hoặc ds1307 bạn muốn sử dụng con nào thì addch/tr của con đó vào
các bạn copy ch/tr này về đặttên và tạo project xong copy các file (dho...asm;quét phim...)vào cùng thư mục chứa project để trình biên dịch tìm nhé.
có ai có thắc mắc tại sao tôi không pos một phát lên không nhỉ ..tự hiểu ...
Đây là file;[ DHO_DS12C887ASM.ASM ] đặt đúng tên này nhé.
; CHUONG TRINH GHI DOC DS12C887
; DONG HO
; GIO EQU 10H
; PHUT EQU 11H
; GIAY EQU 12H
; THU EQU 13H
; NGAY EQU 14H
; THANG EQU 15H
; NAM EQU 16H
;******************
; AM_PM BIT 0X21.0
;****************************************************
DOCDONGHO12C887:
PUSH 00H
;***********
MOV R0,#00H ;DOC GIAY
MOVX A, @R0
MOV GIAY, A;
MOV R0,#02H ;DOC PHUT
MOVX A, @R0
MOV PHUT, A
MOV R0,#04H ;DOC GIO
MOVX A, @r0
MOV GIO, A;
; MOV R0, #06H ;DOC THU
; MOVX A, @R0
; MOV THU, A;
; MOV R0, #07H ; DOC NGAY
; MOVX A,@R0
; MOV NGAY, A
; MOV R0,#08H ;DOC THANG
; MOVX A,@R0
; MOV THANG,A;
; MOV R0,#09H ;DOC NAM
; MOVX A,@R0
; MOV NAM, A
;**************************
MOV A,GIAY
CJNE A,#10H,KT
CLR HOANGIAY
KT: JB HOANGIAY,KT1
CJNE A,#0,_QUA
MOV A,PHUT
CJNE A,#0,_QUA
SETB TITGIO
MOV TAM4,#0
SETB HOANGIAY
KT1:
_QUA:
LCALL DOIBIT12_12_24
POP 00H
RET
;********************************************
;********************************************
;**********c/t con*************
DOC12_24:
MOV R0,#0BH ;DOC 12/24
MOVX A,@R0
MOV C,ACC.1
MOV BIT12,C
LCALL DOIBIT12_12_24
RET
;****************************
KHOITAO:
PUSH 00H
MOV R0,#0AH
MOV A,#00100000b;20H
MOVX @R0,A
; MOV R0,#0BH
; MOV A,#00000000b;02H
; MOVX @R0,A
POP 00H
RET
;************************************
;************************************
DUNG_DHO:
PUSH 00H
MOV R0,#0AH
MOV A,#00H
MOVX @R0,A
POP 00H
RET
;***************************
GHIRESET:
PUSH 00H
MOV A,#13H
MOV R0,#04H
MOVX @R0,A
MOV A,#00H
MOV R0,#02H
MOVX @R0,A
POP 00H
RET
;************************************
;************************************
GHI_GIO: PUSH 00H
MOV R0,#04H
MOVX @R0,A
POP 00H
RET
;************************
GHI_PHUT: PUSH 00H
MOV R0,#02H
MOVX @R0,A
POP 00H
RET
;************************
GHI_GIAY: PUSH 00H
MOV R0,#00H
MOVX @R0,A
POP 00H
RET
;************************
;GHI_THU12887: PUSH 00H
; MOV R0,#06H
; MOVX @R0,A
; POP 00H
; RET
;************************
;GHI_NGAY12887: PUSH 00H
; MOV R0,#07H
; MOVX @R0,A
; RET
;************************
;GHI_THANG12887: PUSH 00H
; MOV R0,#08H
; MOVX @R0,A
; RET
;************************
;GHI_NAM12887: PUSH 00H
; MOV R0,#09H
; MOVX @R0,A
; POP 00H
; RET
;**************************
GHI_12_24:PUSH 00H
MOV R0,#0BH
MOV C,BIT12
MOV ACC.1,C
MOVX @R0,A
POP 00H
RET
;****************************
DOIBIT12_12_24:
JB BIT12,M_24
MOV MODE_NAO,#12H
LCALL DOI_24_TO_12
RET
M_24:MOV MODE_NAO,#24H
LCALL DOI_12_TO_24
RET
;*******************************************
;*******************************************
DOI_12_TO_24:
MOV A,GIO
CJNE A, #01H,K_BANG1N
MOV A, #01H
CLR AM_PM
LJMP THOAT
K_BANG1N:
CJNE A, #02H,K_BANG2N
MOV A,#02H
CLR AM_PM
LJMP THOAT
K_BANG2N:
CJNE A, #03H,K_BANG3N
MOV A,#03H
CLR AM_PM
LJMP THOAT
K_BANG3N:
CJNE A, #04H,K_BANG4N;
MOV A,#04H
CLR AM_PM
LJMP THOAT
K_BANG4N:
CJNE A, #05H,K_BANG5N
MOV A,#05H
CLR AM_PM
LJMP THOAT
K_BANG5N:
CJNE A, #06H,K_BANG6N
MOV A,#06H
CLR AM_PM
LJMP THOAT
K_BANG6N:
CJNE A, #07H,K_BANG7N
MOV A,#07H
CLR AM_PM
LJMP THOAT
K_BANG7N:
CJNE A, #08H,K_BANG8N
MOV A,#08H
CLR AM_PM
LJMP THOAT
K_BANG8N:
CJNE A, #09H,K_BANG9N
MOV A,#09H
CLR AM_PM
LJMP THOAT
K_BANG9N:
CJNE A, #10H,K_BANG10N
MOV A,#10H
CLR AM_PM
LJMP THOAT
K_BANG10N:
CJNE A,#11H,K_BANG11N
MOV A,#11H
CLR AM_PM
LJMP THOAT
K_BANG11N:
CJNE A,#12H,K_BANG12N
MOV A,#12H
CLR AM_PM
LJMP THOAT
K_BANG12N:
CJNE A, #81H,K_BANG13N
MOV A, #13H
SETB AM_PM
LJMP THOAT
K_BANG13N:
CJNE A, #82H,K_BANG14N
MOV A,#14H
SETB AM_PM
LJMP THOAT
K_BANG14N:
CJNE A, #83H,K_BANG15N
MOV A,#15H
SETB AM_PM
LJMP THOAT
K_BANG15N:
CJNE A, #84H,K_BANG16N;
MOV A,#16H
SETB AM_PM
LJMP THOAT
K_BANG16N:
CJNE A,#85H,K_BANG17N
MOV A,#17H
SETB AM_PM
LJMP THOAT
K_BANG17N:
CJNE A, #86H,K_BANG18N
MOV A,#18H
SETB AM_PM
LJMP THOAT
K_BANG18N:
CJNE A, #87H,K_BANG19N
MOV A,#19H
SETB AM_PM
LJMP THOAT
K_BANG19N:
CJNE A,#88H,K_BANG20N
MOV A,#20H
SETB AM_PM
LJMP THOAT
K_BANG20N:
CJNE A, #89H,K_BANG21N
MOV A,#21H
SETB AM_PM
LJMP THOAT
K_BANG21N:
CJNE A, #90H,K_BANG22N
MOV A,#22H
SETB AM_PM
LJMP THOAT
K_BANG22N:
CJNE A,#91H,K_BANG23N
MOV A,#23H
SETB AM_PM
LJMP THOAT
K_BANG23N:
CJNE A,#92H,THOATN
MOV A,#00H
SETB AM_PM
THOATN: MOV GIO,A
RET
;*******************************************
;*******************************************
DOI_24_TO_12:
MOV A,GIO
CJNE A, #01H,K_BANG1
MOV A, #01H
CLR AM_PM
LJMP THOAT
K_BANG1:
CJNE A, #02H,K_BANG2
MOV A,#02H
CLR AM_PM
LJMP THOAT
K_BANG2:
CJNE A, #03H,K_BANG3
MOV A,#03H
CLR AM_PM
LJMP THOAT
K_BANG3:
CJNE A, #04H,K_BANG4;
MOV A,#04H
CLR AM_PM
LJMP THOAT
K_BANG4:
CJNE A, #05H,K_BANG5
MOV A,#05H
CLR AM_PM
LJMP THOAT
K_BANG5:
CJNE A, #06H,K_BANG6
MOV A,#06H
CLR AM_PM
LJMP THOAT
K_BANG6:
CJNE A, #07H,K_BANG7
MOV A,#07H
CLR AM_PM
LJMP THOAT
K_BANG7:
CJNE A, #08H,K_BANG8
MOV A,#08H
CLR AM_PM
LJMP THOAT
K_BANG8:
CJNE A, #09H,K_BANG9
MOV A,#09H
CLR AM_PM
LJMP THOAT
K_BANG9:
CJNE A, #10H,K_BANG10
MOV A,#10H
CLR AM_PM
LJMP THOAT
K_BANG10:
CJNE A,#11H,K_BANG11
MOV A,#11H
CLR AM_PM
LJMP THOAT
K_BANG11:
CJNE A,#12H,K_BANG12
MOV A,#12H
CLR AM_PM
LJMP THOAT
K_BANG12:
CJNE A, #13H,K_BANG13
MOV A, #81H
SETB AM_PM
LJMP THOAT
K_BANG13:
CJNE A, #14H,K_BANG14
MOV A,#82H
SETB AM_PM
LJMP THOAT
K_BANG14:
CJNE A, #15H,K_BANG15
MOV A,#83H
SETB AM_PM
LJMP THOAT
K_BANG15:
CJNE A, #16H,K_BANG16;
MOV A,#84H
SETB AM_PM
LJMP THOAT
K_BANG16:
CJNE A, #17H,K_BANG17
MOV A,#85H
SETB AM_PM
LJMP THOAT
K_BANG17:
CJNE A, #18H,K_BANG18
MOV A,#86H
SETB AM_PM
LJMP THOAT
K_BANG18:
CJNE A, #19H,K_BANG19
MOV A,#87H
SETB AM_PM
LJMP THOAT
K_BANG19:
CJNE A, #20H,K_BANG20
MOV A,#88H
SETB AM_PM
LJMP THOAT
K_BANG20:
CJNE A, #21H,K_BANG21
MOV A,#89H
SETB AM_PM
LJMP THOAT
K_BANG21:
CJNE A, #22H,K_BANG22
MOV A,#90H
SETB AM_PM
LJMP THOAT
K_BANG22:
CJNE A,#23H,K_BANG23
MOV A,#91H
SETB AM_PM
LJMP THOAT
K_BANG23:
CJNE A,#00H,THOAT
MOV A,#92H
SETB AM_PM
THOAT: MOV GIO,A
RET
;*******************************************
;*******************************************
;*******************************************
Đây là file;[ DHO_DS1307ASM.ASM ] đặt đúng tên này nhé.
; CHUONG TRINH GHI DOC DS1307 DALAS
; DONG HO
; GIO EQU 10H
; PHUT EQU 11H
; GIAY EQU 12H
; THU EQU 13H
; NGAY EQU 14H
; THANG EQU 15H
; NAM EQU 16H
;******************
; AM_PM BIT 0X21.0
;****************************************************
; SDA BIT P3.0 ;BIT DATA;Khai bao phu hop phan cung
; SCL BIT P3.1 ;XUNG CLOCK
;*****************************
;=============================
DOCDONGHODS1307:
LCALL DOC_GIAY
LCALL DOC_PHUT
LCALL DOC_GIO
MOV A,GIAY
CJNE A,#10H,KT
CLR HOANGIAY
KT: JB HOANGIAY,KT1
CJNE A,#0,_QUA
MOV A,PHUT
CJNE A,#0,_QUA
SETB TITGIO
MOV TAM4,#0
SETB HOANGIAY
KT1:
_QUA:
LCALL DOIBIT12_12_24
RET
;******************
DOC12_24:
MOV A,GIO
MOV C,ACC.6
CPL BIT12
MOV BIT12,C
RET
;******************
DUNG_DHO:
MOV A,#0D0H ;DIA CHI CUA RTC1307, D0 = GHI, D1 = DOC
LCALL START
LCALL GUI_BYTE
MOV A,#00H
LCALL GUI_BYTE
MOV A,GIAY
CLR ACC.7
LCALL GUI_BYTE
LCALL STOP
RET
;******************
KHOITAO:
RET
;********************************************
;*Doc gio,phut,giay,can thi them ngày ,thang,..v.v
;================================================= ===
DOC_GIAY:
PUSH 06H
LCALL GUI_0D0H
MOV A,#00H ;DIA CHI CUA GIA TRONG RTC1307
LCALL GUI_0D1H
MOV GIAY,R6
POP 06H
RET
;********************************************
DOC_PHUT:
PUSH 06H
LCALL GUI_0D0H
MOV A,#01H ;DIA CHI CUA PHUT TRONG RTC1307
LCALL GUI_0D1H
MOV PHUT,R6
POP 06H
RET
;********************************************
DOC_GIO:
PUSH 06H
LCALL GUI_0D0H
MOV A,#02H ;DIA CHI CUA GIO TRONG RTC1307
LCALL GUI_0D1H
MOV GIO,R6
POP 06H
RET
;*************************************
GUI_0D0H:
MOV A,#0D0H ;DIA CHI CUA RTC1307, D0 = GHI, D1 = DOC
LCALL START
LCALL GUI_BYTE
RET
;**********
GUI_0D1H:
LCALL GUI_BYTE
LCALL STOP
MOV A,#0D1H ;NHAN DATA SECONDS TU RTC1307
LCALL START
LCALL GUI_BYTE
LCALL NHAN_BYTE
LCALL STOP
RET
;***************************************************************
;***************************************************************
;==========Chuong trinh ghivao ds1307==========================
;***************************8
GHI_GIO:
MOV A,#0D0H ;DIA CHI CUA RTC1307, D0 = GHI, D1 = DOC
LCALL START
LCALL GUI_BYTE
MOV A,#02H
LCALL GUI_BYTE
MOV A,GIO
ANL A,#00111111B
LCALL GUI_BYTE
LCALL STOP
RET
;***************************8
GHI_PHUT:
MOV A,#0D0H ;DIA CHI CUA RTC1307, D0 = GHI, D1 = DOC
LCALL START
LCALL GUI_BYTE
MOV A,#01H
LCALL GUI_BYTE
MOV A,PHUT
LCALL GUI_BYTE
LCALL STOP
RET
;***************************8
GHI_GIAY:
MOV A,#0D0H ;DIA CHI CUA RTC1307, D0 = GHI, D1 = DOC
LCALL START
LCALL GUI_BYTE
MOV A,#00H
LCALL GUI_BYTE
MOV A,GIAY
LCALL GUI_BYTE
LCALL STOP
RET
;*************************************************
;++++++++++++++++++++++++++++++++++++++++++
;**********chuong trinh con i2c cho ds1307**
START:
CLR SCL
SETB SDA
NOP
NOP
NOP
SETB SCL
CLR SDA
NOP
NOP
NOP
RET
;****************************
STOP:
NOP
NOP
NOP
CLR SDA
SETB SCL
NOP
SETB SDA
NOP
NOP
NOP
CLR SCL
ret
;************************************
;************************************
GUI_BYTE:
MOV R7,#8
BACK_GUI:
CLR SCL
NOP
NOP
NOP
RLC A
MOV SDA,C
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
DJNZ R7,BACK_GUI
SETB SDA
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
RET
;******************************
; OUT R6
;*****************************
NHAN_BYTE:
MOV R7,#08
BACK_NHAN:
SETB SCL
NOP
NOP
NOP
MOV C,SDA
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
MOV A,R6
RLC A
MOV R6,A
DJNZ R7,BACK_NHAN
SETB SDA
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
CLR SCL
NOP
NOP
NOP
RET
;**************************
GHI_12_24:PUSH 00H
PUSH ACC
MOV A,GIO ;
ANL A,#10111111B
MOV C,BIT12
CPL C
MOV ACC.6,C
LCALL GHI_GIO
POP ACC
POP 00H
RET
;****************************
DOIBIT12_12_24:
JB BIT12,M_24
MOV MODE_NAO,#12H
LCALL DOI_24_TO_12
RET
M_24:MOV MODE_NAO,#24H
LCALL DOI_12_TO_24
RET
;*******************************************
;*******************************************
DOI_12_TO_24:
MOV A,GIO
CJNE A, #01H,K_BANG1N
MOV A, #01H
CLR AM_PM
LJMP THOAT
K_BANG1N:
CJNE A, #02H,K_BANG2N
MOV A,#02H
CLR AM_PM
LJMP THOAT
K_BANG2N:
CJNE A, #03H,K_BANG3N
MOV A,#03H
CLR AM_PM
LJMP THOAT
K_BANG3N:
CJNE A, #04H,K_BANG4N;
MOV A,#04H
CLR AM_PM
LJMP THOAT
K_BANG4N:
CJNE A, #05H,K_BANG5N
MOV A,#05H
CLR AM_PM
LJMP THOAT
K_BANG5N:
CJNE A, #06H,K_BANG6N
MOV A,#06H
CLR AM_PM
LJMP THOAT
K_BANG6N:
CJNE A, #07H,K_BANG7N
MOV A,#07H
CLR AM_PM
LJMP THOAT
K_BANG7N:
CJNE A, #08H,K_BANG8N
MOV A,#08H
CLR AM_PM
LJMP THOAT
K_BANG8N:
CJNE A, #09H,K_BANG9N
MOV A,#09H
CLR AM_PM
LJMP THOAT
K_BANG9N:
CJNE A, #10H,K_BANG10N
MOV A,#10H
CLR AM_PM
LJMP THOAT
K_BANG10N:
CJNE A,#11H,K_BANG11N
MOV A,#11H
CLR AM_PM
LJMP THOAT
K_BANG11N:
CJNE A,#12H,K_BANG12N
MOV A,#12H
CLR AM_PM
LJMP THOAT
K_BANG12N:
CJNE A, #81H,K_BANG13N
MOV A, #13H
SETB AM_PM
LJMP THOAT
K_BANG13N:
CJNE A, #82H,K_BANG14N
MOV A,#14H
SETB AM_PM
LJMP THOAT
K_BANG14N:
CJNE A, #83H,K_BANG15N
MOV A,#15H
SETB AM_PM
LJMP THOAT
K_BANG15N:
CJNE A, #84H,K_BANG16N;
MOV A,#16H
SETB AM_PM
LJMP THOAT
K_BANG16N:
CJNE A,#85H,K_BANG17N
MOV A,#17H
SETB AM_PM
LJMP THOAT
K_BANG17N:
CJNE A, #86H,K_BANG18N
MOV A,#18H
SETB AM_PM
LJMP THOAT
K_BANG18N:
CJNE A, #87H,K_BANG19N
MOV A,#19H
SETB AM_PM
LJMP THOAT
K_BANG19N:
CJNE A,#88H,K_BANG20N
MOV A,#20H
SETB AM_PM
LJMP THOAT
K_BANG20N:
CJNE A, #89H,K_BANG21N
MOV A,#21H
SETB AM_PM
LJMP THOAT
K_BANG21N:
CJNE A, #90H,K_BANG22N
MOV A,#22H
SETB AM_PM
LJMP THOAT
K_BANG22N:
CJNE A,#91H,K_BANG23N
MOV A,#23H
SETB AM_PM
LJMP THOAT
K_BANG23N:
CJNE A,#92H,THOATN
MOV A,#00H
SETB AM_PM
THOATN: MOV GIO,A
RET
;*******************************************
;*******************************************
DOI_24_TO_12:
MOV A,GIO
CJNE A, #01H,K_BANG1
MOV A, #01H
CLR AM_PM
LJMP THOAT
K_BANG1:
CJNE A, #02H,K_BANG2
MOV A,#02H
CLR AM_PM
LJMP THOAT
K_BANG2:
CJNE A, #03H,K_BANG3
MOV A,#03H
CLR AM_PM
LJMP THOAT
K_BANG3:
CJNE A, #04H,K_BANG4;
MOV A,#04H
CLR AM_PM
LJMP THOAT
K_BANG4:
CJNE A, #05H,K_BANG5
MOV A,#05H
CLR AM_PM
LJMP THOAT
K_BANG5:
CJNE A, #06H,K_BANG6
MOV A,#06H
CLR AM_PM
LJMP THOAT
K_BANG6:
CJNE A, #07H,K_BANG7
MOV A,#07H
CLR AM_PM
LJMP THOAT
K_BANG7:
CJNE A, #08H,K_BANG8
MOV A,#08H
CLR AM_PM
LJMP THOAT
K_BANG8:
CJNE A, #09H,K_BANG9
MOV A,#09H
CLR AM_PM
LJMP THOAT
K_BANG9:
CJNE A, #10H,K_BANG10
MOV A,#10H
CLR AM_PM
LJMP THOAT
K_BANG10:
CJNE A,#11H,K_BANG11
MOV A,#11H
CLR AM_PM
LJMP THOAT
K_BANG11:
CJNE A,#12H,K_BANG12
MOV A,#12H
CLR AM_PM
LJMP THOAT
K_BANG12:
CJNE A, #13H,K_BANG13
MOV A, #81H
SETB AM_PM
LJMP THOAT
K_BANG13:
CJNE A, #14H,K_BANG14
MOV A,#82H
SETB AM_PM
LJMP THOAT
K_BANG14:
CJNE A, #15H,K_BANG15
MOV A,#83H
SETB AM_PM
LJMP THOAT
K_BANG15:
CJNE A, #16H,K_BANG16;
MOV A,#84H
SETB AM_PM
LJMP THOAT
K_BANG16:
CJNE A, #17H,K_BANG17
MOV A,#85H
SETB AM_PM
LJMP THOAT
K_BANG17:
CJNE A, #18H,K_BANG18
MOV A,#86H
SETB AM_PM
LJMP THOAT
K_BANG18:
CJNE A, #19H,K_BANG19
MOV A,#87H
SETB AM_PM
LJMP THOAT
K_BANG19:
CJNE A, #20H,K_BANG20
MOV A,#88H
SETB AM_PM
LJMP THOAT
K_BANG20:
CJNE A, #21H,K_BANG21
MOV A,#89H
SETB AM_PM
LJMP THOAT
K_BANG21:
CJNE A, #22H,K_BANG22
MOV A,#90H
SETB AM_PM
LJMP THOAT
K_BANG22:
CJNE A,#23H,K_BANG23
MOV A,#91H
SETB AM_PM
LJMP THOAT
K_BANG23:
CJNE A,#00H,THOAT
MOV A,#92H
SETB AM_PM
THOAT: MOV GIO,A
RET
;*******************************************
Day file<LOAD_DATA_QUETLED5X7ASM.ASM>
Code:
;========================================================QUETLED: CJNE MODE_K,#1,KHAC LCALL LOADMODE12_24 RETKHAC:;************LOA DATA GIO,PHUT GIAY VAO RAM******************;============================================================LOADGIOPHUTGIAY: CJNE MODE_K,#0,KTG;hien thi binh thuong mode_k=0MOV TAM1,GIOLJMP LEDGIOKTG: CJNE MODE_K,#2,LEDGIO;KL_X LCALL CHOPSANG ; neu x>40 thi tat ledJC LEDGIOMOV A,#0AAHMOV TAM1,#0AAHJMP CHOPGIOLEDGIO: MOV A,TAM1CHOPGIO: MOV R0,#30H;30H ;Dia chi dau;*********************** ; MOV A,GIO ;c5 LCALL LOADLEDN_CHUC_BOSO_0 ;gio chuc mau do;*********** lcall laygiohienthi LCALL COTTRONG ;C6;*********** MOV 2AH,TAM1MOV A,TAM1;GIO ;c11 LCALL LOADLEDN_DONVI ;gio donviMOV TAM1,GIO;***********LCALL TRONGCHAM_N ;C14;*********************************** CJNE MODE_K,#2,_RETJB BIT12,_RET LCALL LODEAM_PMLCALL QUET7HANGRET_RET:;*********************************** CJNE MODE_K,#0,KTPMOV TAM2,PHUTLJMP LEDPHUTKTP: CJNE MODE_K,#3,LEDPHUT LCALL CHOPSANG ; neu x>40 thi tat ledJC LEDPHUTMOV A,#0AAHMOV TAM2,#0AAHJMP CHOPPHUT mov tam2,#0aah;LEDPHUT: MOV A,TAM2CHOPPHUT: LCALL LOADLEDN_CHUC ;phut chuc;*********** LCALL COTTRONG ;C20;***********MOV A,TAM2 ;c25 LCALL LOADLEDN_DONVI ;phut donvi MOV TAM2,PHUT;****************LCALL TRONGCHAM_N ;C28;******************************;******************************* CJNE MODE_K,#0,KTGIMOV TAM3,GIAYLJMP LEDGIAYKTGI: CJNE MODE_K,#4,LEDGIAY LCALL CHOPSANG ; neu x>40 thi tat ledJC LEDGIAYMOV A,#0AAHMOV TAM3,#0AAHJMP CHOPGIAY mov tam3,#0aah;LEDGIAY: MOV A,TAM3;NGAYCHOPGIAY: LCALL LOADLEDN_CHUC ;giay chuc;*********** LCALL COTTRONG ;C34;***********MOV A,TAM3 ;c39 LCALL LOADLEDN_DONVI;giay donvi MOV TAM3,GIAY;*********************LCALL COTTRONG ;40;*********************** LCALL QUET7HANG;********************RET;***************************************************;***************************************************;************LOA DATA MODE HOUR AM/PM VAO RAM*******LODEAM_PM: ;GIO 11 COT JB AM_PM,QUA_PMLCALL LODECHU_AM ;bit AM_PM =0 la AMRETQUA_PM: LCALL LODECHU_PM RET;**********************LODECHU_AM: PUSH 01H MOV DPTR,#BANG_AM;25byte MOV R1,#0 MOV A,R1 LL_AM: MOVC A, @A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1 CJNE R1,#30,LL_AM POP 01H RET ;************************LODECHU_PM: PUSH 01H MOV DPTR,#BANG_PM;25byte MOV R1,#0 MOV A,R1 LL_PM: MOVC A, @A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1 CJNE R1,#30,LL_PM POP 01H RET ;************LOA DATA MODE HOUR 12/24 VAO RAM******************;============================================================LOADMODE12_24: MOV R0,#30H;30H ;Dia chi dau LCALL LODECHUHOURS ;29 COTMOV A,MODE_NAOLCALL LOADLEDN_CHUCLCALL COTTRONG ;1 COTMOV A,MODE_NAOLCALL LOADLEDN_DONVILCALL QUET7HANGRET;******************************LODECHUHOURS: PUSH 01H MOV DPTR,#BANG_HOUR ;25byte MOV R1,#0 MOV A,R1LL_HOURS: MOVC A, @A+DPTR ; SWAP A MOV @R0,A INC R0 INC R1 MOV A,R1 CJNE R1,#29,LL_HOURS POP 01H RET ;****************************;***************************************************;***************************************************;***************************************************;***************************************************laygiohienthi:; TAM1 don vi;GIOH_THI hang chuc push 01hmov a,GIOH_THImov r1,#2AHswap axchd a,@r1mov GIOH_THI,a pop 01h ret;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&;***********************************************QUET7HANG: PUSH 07H PUSH 00H MOV R7,#7 ;chonhang LAPHANG: MOV R0,#30H ;30H>>81H CLR RCK LAPCOT: CLR SCK
MOV A,@R0
CLR C RRC A MOV @R0,A SETB SCK MOV SI,C INC R0 CJNE R0,#59H,LAPCOT SETB RCK MOV CHONHANG,R7;Sang hang LCALL DELAYLED MOV CHONHANG,#0 DJNZ R7,LAPHANG POP 00H POP 07H RET ;***********;***********************************************;*********************************************** boso8_9: cjne a,#8,no1mov a,#0ret no1:cjne a,#9,himov a,#1hi :ret;*********************************************************LOADLEDN_CHUC_BOSO_0:push 02h PUSH 01H MOV DPTR,#BANG_SO_NHO;hangchuc ANL A, #0F0H SWAP A lcall boso8_9 mov GIOH_THI,a ;luu tam giohien thi SO H CHUC MOV B,#5 MUL AB cjne a,#0,no mov a,#50 no: MOV R1,A MOV R2,#5 LAPLAIB: MOVC A,@A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1
DJNZ R2,LAPLAIB POP 01H POP 02H RET;*******************************************LOADLEDN_DONVI: push 02h PUSH 01H MOV DPTR,#BANG_SO_NHO ;don vi ANL A,#0FH MOV B,#5 MUL AB MOV R1,A MOV R2,#5LAPLAI1_N: MOVC A, @A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1 DJNZ R2,LAPLAI1_N POP 01H POP 02H RET ;*******************************************LOADLEDN_CHUC: push 02h PUSH 01H MOV DPTR,#BANG_SO_NHO;hangchuc ANL A, #0F0H SWAP A MOV B,#5 MUL AB MOV R1,A MOV R2,#5 LAPLAIN: MOVC A, @A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1 DJNZ R2,LAPLAIN POP 01H POP 02H RET;******************************************* TRONGCHAM_N:push 02h PUSH 01H MOV DPTR,#BANG_SO_NHO ;trong cham MOV A,#55 MOV R1,A MOV R2,#3LAPLAITR_N:MOVC A, @A+DPTR MOV @R0,A INC R0 INC R1 MOV A,R1 DJNZ R2,LAPLAITR_N POP 01H POP 02H RET;****************************************** CHAMCHOP: MOV A,1FH MOV @R0,AINC R0RET;********************************COTTRONG: mov a,#0 ;cot trong mov @R0,a inc r0 RET;*******************************DELAYLED: PUSH 04H PUSH 03H MOV R4,#10;4;2 D1 : MOV R3,#250 DJNZ R3,$ DJNZ R4,D1 POP 03H POP 04H RET ;***************************;*************BANG_SO_NHO : DB 3EH,7FH,41H,7FH,3Eh DB 11H,21H,7FH,7FH,01h DB 23H,67H,4DH,79H,31h DB 22H,63H,49H,7FH,36h DB 0EH,1AH,32H,7FH,7Fh DB 72H,73H,51H,5FH,4eh DB 3EH,7FH,49H,6FH,26h DB 43H,47H,4cH,78H,70h DB 36H,7FH,49H,7FH,36h DB 32H,7BH,49H,7FH,3Eh DB 00H,00H,00H,00H,00H DB 00H,14H,00H ;************* BANG_AM: DB 0h,0H,0H,1FH,3FH,28H,3FH,1FH,0H,3FH DB 3FH,20H,3FH,3FH,20H,3FH,1FH ,0H,0H,0H ;AM 20BYTE DB 0H,0H,0H,0H,0H,0H,0H,0H,0H,0H,0H BANG_PM: DB 0H,0H,0H,3FH,3FH,24H,3CH,18H,0H,3FH DB 3FH,20H,3FH,3FH,20H,3FH,1FH,0H,0H,0H;PM DB 0H,0H,0H,0H,0H,0H,0H,0H,0H,0H,0H;*************BANG_HOUR: DB 7FH,7FH,10H,1FH,0FH,0H,0EH,1FH,11H,1FH,0EH,0H DB 1EH,1FH,1H,1EH,1FH,0H,1FH,1FH,8H,10H,8H,0H;HUUR 24BYTE DB 8H,2AH,1CH,8H,0H ;5B
ch/tr [QUETPHIMCHINHGIOPHUTGIAY.ASM]
Code:
; ***** CHUONG TRÌNH QUÉT PHIM ******; SET0 BIT 0x20.5; SET1 BIT 0x20.0; UP0 BIT 0x20.1; UP1 BIT 0x20.2; DOWN0 BIT 0x20.3; DOWN1 BIT 0x20.4;***************************************************;***************************************************;***************************************************;***************************************************;***************************************************KT_PHIM:;=================== ; set0=set1;set1=set;//Kiem tra trang thai ban dau cua phim MOV C,set1;set1 MOV set0,C MOV C,PHIMSE;set MOV set1,C;if((set0==1)&&(set1==0))//Kiem tra xem phim co dc nhan nha hay khong JNB set0,_001D;//Neu dc nhan nha thi tang kt++,neu khong thi JB set1,_001D;kt++;if(kt>3)kt=0;//doi toi khi nao phim dc nha moi tang bienkt ;************** INC MODE_K LCALL DUNG_DHO LCALL BET MOV A,MODE_K SETB C SUBB A,#4 ;4mode chinh JC _001D MOV MODE_K,#0 MOV CHE_DO,#0 LCALL KHOITAO RET;*************** _001D:T_PHIM: MOV A,MODE_K ;Lua chon che do ung voi gia tri cua bien ktCJNE A,#1,TIM_K0 LJMP CHINH12_24TIM_K0: CJNE A,#2,TIM_K1 LJMP CHINHGIOTIM_K1: CJNE A,#3,TIM_K2 LJMP CHINHPHUT TIM_K2: CJNE A,#4,T_E LJMP CHINHGIAY T_E: RET
;-===========================================;*******************************************CHINHGIO: MOV C,up1 MOV up0,C MOV C,PHIMUP MOV up1,C MOV CHE_DO,#1 JNB up0,_004A JB up1,_004A MOV A, GIO LCALL _INC;INC MOV GIO,A;************************ jb BIT12,K_0a cjne a,#01h,k_0b clr am_pm jmp k_0ak_0b: cjne a,#13h,K_0c mov gio,#81h setb am_pm mov a,gioK_0c: cjne a,#93h,k_0a mov gio,#01h clr am_pm ljmp k_0a;!!!!!!!!!! K_0a: jnb BIT12,_004A0 SETB C SUBB A,#23H JC _004A0 CLR A MOV GIO,A LJMP GHI_H_004A0: MOV A,GIOGHI_H: LCALL GHI_GIO;************ _004A: MOV C,down1 ;down0=down1;down1=down;// MOV down0,C MOV C,PHIMDN MOV down1,C JNB down0,_00D71;if((down0==1)&&(down1==0))
JB down1,_00D71 MOV A, GIO LCALL _DEC;DEC MOV GIO,A;!!!!! jb BIT12,d_0a cjne a,#92h,d_0b setb am_pm jmp d_0ad_0b: cjne a,#80h,d_0c mov gio,#12h clr am_pm mov a,giod_0c: cjne a,#0h,d_0d mov gio,#92h setb am_pmd_0d: ljmp _00D70;!!!!!!!!!! d_0a: SETB C SUBB A,#23H JC _00D70d_1: MOV GIO,#23Hd_02: _00D70: MOV A,GIO LCALL GHI_GIO_00D71: RET ;*******************************************;******************************************* CHINHPHUT:MOV C,up1 MOV up0,C MOV C,PHIMUP MOV up1,C MOV CHE_DO,#1 JNB up0,_0085 JB up1,_0085 MOV A,PHUTLCALL _INC;INCMOV PHUT,A SETB C SUBB A,#59H JC _0085A CLR AMOV PHUT,ALJMP GHI_P_0085A:MOV A,PHUT GHI_P:LCALL GHI_PHUT;******************** _0085: MOV C,down1 MOV down0,C MOV C,PHIMDN MOV down1,C JNB down0,_00D7GP JB down1,_00D7GP MOV A,PHUT LCALL _DEC ; DEC PHUT MOV PHUT,A SETB C SUBB A,#59H JC _00D7p MOV PHUT,#59H_00D7p: MOV A,PHUT LCALL GHI_PHUT _00D7GP:RET ; break; ;*******************************************;******************************************* CHINHGIAY:MOV C,up1;case 3: //Che do cai dat giay MOV up0,C ;up0=up1;up1=up;a=1; MOV C,PHIMUP;up MOV up1,C MOV CHE_DO,#1 JNB up0,_00BD;if((up0==1)&&(up1==0)) JB up1,_00BD MOV A,GIAYLCALL _INC;INCMOV GIAY,A SETB C SUBB A,#59H JC _00BDS CLR A MOV GIAY,ALJMP GHI_S_00BDS:MOV A,GIAY GHI_S:LCALL GHI_GIAY;********************
_00BD: MOV C,down1 ; down0=down1;down1=down; MOV down0,C MOV C,PHIMDN MOV down1,C JNB down0,_00D7GS;if((down0==1)&&(down1==0)) JB down1,_00D7GS MOV A,GIAYLCALL _DEC;DECMOV GIAY,A SETB C SUBB A,#59H JC _00D7S MOV GIAY,#59H_00D7S: MOV A,GIAY LCALL GHI_GIAY _00D7GS: RET ;*****************************************;*******************************************CHINH12_24: MOV C,up1 MOV up0,C ;up0=up1;up1=up;a=1; MOV C,PHIMUP;up MOV up1,C MOV CHE_DO,#1 JNB up0,_0012 JB up1,_0012 CPL BIT12 LCALL DOIBIT12_12_24LJMP GHI12;********************
_0012: MOV C,down1 ; down0=down1;down1=down; MOV down0,C MOV C,PHIMDN MOV down1,C JNB down0,_00D12;if((down0==1)&&(down1==0)) JB down1,_00D12 CPL BIT12LCALL DOIBIT12_12_24_00D12:GHI12: LCALL GHI_12_24 RET ;*****************************************_INC:ADD A,#1HDA ARET;******_DEC:ADD A,#99HDA ARET